﻿package mortal.game.view.common.menu
{
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.system.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.info.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.utils.*;
    import mortal.game.view.flowerSend.data.*;
    import mortal.mvc.core.*;

    public class PlayerMenuConst extends Object
    {
        public static const ChatForbid:String = Language.getString(20727);
        public static const ChatUnForbid:String = Language.getString(20728);
        public static const ChatPirvate:String = Language.getString(20729);
        public static const LookInfo:String = Language.getString(20730);
        public static const AddFriend:String = Language.getString(20731);
        public static const AddIntimateFriend:String = Language.getString(20732);
        public static const LowerToFriend:String = Language.getString(20733);
        public static const Trade:String = Language.getString(20734);
        public static const SendLetter:String = Language.getString(20735);
        public static const CopyName:String = Language.getString(20736);
        public static const InvitedToTeam:String = Language.getString(20737);
        public static const ApplyToTeam:String = Language.getString(20738);
        public static const GuildInvite:String = Language.getString(20739);
        public static const GuildInviteCreate:String = Language.getString(20740);
        public static const GuildApply:String = Language.getString(20741);
        public static const MoveToBlackList:String = Language.getString(20742);
        public static const LeaveGroup:String = Language.getString(20743);
        public static const KickOutGroup:String = Language.getString(20744);
        public static const AppointCaptain:String = Language.getString(20745);
        public static const HandselFlower:String = Language.getString(20746);
        public static const LookMember:String = Language.getString(20747);
        public static const Battle:String = Language.getString(20748);
        public static const ChristmasCard:String = Language.getString(20749);
        public static const CreateGroup:String = Language.getString(20750);
        public static const DisBandGroup:String = Language.getString(20751);
        public static const Delete:String = Language.getString(20752);
        public static const Delete2:String = Language.getString(20753);
        public static const Remove:String = Language.getString(20754);
        public static const FlowerSend:String = Language.getString(20755);
        private static const cache:Cache = Cache.instance;
        public static var ChatOpMenu:DataProvider = new DataProvider([{label:ChatForbid}, {label:ChatUnForbid}, {label:ChatPirvate}, {label:AddFriend}, {label:LookInfo}, {label:Trade}, {label:SendLetter}, {label:CopyName}, {label:InvitedToTeam}, {label:ApplyToTeam}, {label:GuildInvite}, {label:GuildApply}, {label:Battle}, {label:MoveToBlackList}, {label:GuildInviteCreate}, {label:FlowerSend}]);
        public static var ChatPrivateOpMenu:DataProvider = new DataProvider([{label:ChatForbid}, {label:ChatUnForbid}, {label:AddFriend}, {label:LookInfo}, {label:Trade}, {label:SendLetter}, {label:CopyName}, {label:InvitedToTeam}, {label:ApplyToTeam}, {label:GuildInvite}, {label:GuildApply}, {label:Battle}, {label:MoveToBlackList}, {label:FlowerSend}]);
        public static var FriendOpMenu:DataProvider = new DataProvider([{label:ChatPirvate}, {label:LookInfo}, {label:Trade}, {label:SendLetter}, {label:CopyName}, {label:InvitedToTeam}, {label:ApplyToTeam}, {label:GuildInvite}, {label:GuildApply}, {label:Delete}, {label:MoveToBlackList}, {label:AddIntimateFriend}, {label:GuildInviteCreate}, {label:FlowerSend}]);
        public static var IntimateFriendOpMenu:DataProvider = new DataProvider([{label:ChatPirvate}, {label:LookInfo}, {label:Trade}, {label:SendLetter}, {label:CopyName}, {label:InvitedToTeam}, {label:ApplyToTeam}, {label:GuildInvite}, {label:GuildApply}, {label:Delete}, {label:MoveToBlackList}, {label:LowerToFriend}, {label:FlowerSend}]);
        public static var EnemyOpMenu:DataProvider = new DataProvider([{label:ChatPirvate}, {label:LookInfo}, {label:Trade}, {label:SendLetter}, {label:CopyName}, {label:InvitedToTeam}, {label:ApplyToTeam}, {label:Delete2}, {label:MoveToBlackList}, {label:FlowerSend}]);
        public static var BlackListOpMenu:DataProvider = new DataProvider([{label:AddFriend}, {label:LookInfo}, {label:CopyName}, {label:Delete2}]);
        public static var RecentListOpMenu:DataProvider = new DataProvider([{label:ChatPirvate}, {label:LookInfo}, {label:Trade}, {label:SendLetter}, {label:CopyName}, {label:InvitedToTeam}, {label:ApplyToTeam}, {label:GuildInvite}, {label:GuildApply}, {label:Remove}, {label:MoveToBlackList}, {label:ChristmasCard}, {label:FlowerSend}]);
        public static var GroupSelfOpMenu:DataProvider = new DataProvider([{label:CopyName}, {label:CreateGroup}, {label:LeaveGroup}, {label:DisBandGroup}]);
        public static var GroupMemberOpMenu:DataProvider = new DataProvider([{label:CopyName}, {label:ChatPirvate}, {label:LookInfo}, {label:Trade}, {label:SendLetter}, {label:KickOutGroup}, {label:LeaveGroup}, {label:AppointCaptain}, {label:AddFriend}, {label:Delete}, {label:MoveToBlackList}, {label:GuildInviteCreate}, {label:FlowerSend}]);
        public static var NearbyPlayerOpMenu:DataProvider = new DataProvider([{label:CopyName}, {label:InvitedToTeam}, {label:ApplyToTeam}, {label:AddFriend}, {label:ChatPirvate}, {label:Battle}, {label:LookInfo}, {label:SendLetter}, {label:Trade}, {label:GuildInvite}, {label:GuildApply}, {label:GuildInviteCreate}, {label:FlowerSend}]);
        public static var GuildMemberOnlineOpMenu:DataProvider = new DataProvider([{label:ChatPirvate}, {label:LookInfo}, {label:Trade}, {label:SendLetter}, {label:CopyName}, {label:InvitedToTeam}, {label:ApplyToTeam}, {label:MoveToBlackList}, {label:FlowerSend}, {label:AddFriend}]);
        public static var GuildMemberOfflineOpMenu:DataProvider = new DataProvider([{label:SendLetter}, {label:CopyName}, {label:MoveToBlackList}]);

        public function PlayerMenuConst()
        {
            return;
        }// end function

        public static function getEnabeldAttri(param1:DataProvider, param2) : DataProvider
        {
            var _loc_5:Object = null;
            var _loc_6:Boolean = false;
            var _loc_7:Object = null;
            var _loc_3:* = new DataProvider();
            var _loc_4:int = 0;
            while (_loc_4 < param1.length)
            {
                
                _loc_5 = param1.getItemAt(_loc_4);
                _loc_6 = getOpEnabled(_loc_5["label"], param2);
                if (_loc_6)
                {
                    _loc_7 = {label:_loc_5["label"], enabled:_loc_6};
                    _loc_3.addItem(_loc_7);
                }
                _loc_4++;
            }
            return _loc_3;
        }// end function

        private static function getMiniPlayerByData(param1) : SMiniPlayer
        {
            var _loc_2:SMiniPlayer = null;
            var _loc_3:SFriendRecord = null;
            var _loc_4:SPublicPlayer = null;
            var _loc_5:SGroupPlayer = null;
            var _loc_6:EntityInfo = null;
            if (param1 is SMiniPlayer)
            {
                _loc_2 = param1 as SMiniPlayer;
            }
            if (param1 is SFriendRecord)
            {
                _loc_3 = param1 as SFriendRecord;
                _loc_2 = PlayerUtil.convertToMiniPlayerInfo(_loc_3);
            }
            else if (param1 is SPublicPlayer)
            {
                _loc_4 = param1 as SPublicPlayer;
                _loc_2 = PlayerUtil.copyPubicToMiniPlayer(_loc_4);
            }
            else if (param1 is SGroupPlayer)
            {
                _loc_5 = param1 as SGroupPlayer;
                _loc_2 = PlayerUtil.copyPubicToMiniPlayer(_loc_5.player);
            }
            else if (param1 is EntityInfo)
            {
                _loc_6 = param1 as EntityInfo;
                _loc_2 = PlayerUtil.copyEntityInfoToMiniPlayer(_loc_6.entityInfo);
            }
            return _loc_2;
        }// end function

        public static function Opearte(param1:String, param2) : void
        {
            var onClickHandler:Function;
            var arr:Array;
            var sGroupOper:SGroupOper;
            var arr2:Array;
            var sGroupOper2:SGroupOper;
            var flowerData:FlowerSendData;
            var opName:* = param1;
            var playerData:* = param2;
            onClickHandler = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.FriendDeleteRecord, playerData));
                }
                else
                {
                    return;
                }
                return;
            }// end function
            ;
            var miniPlayer:* = getMiniPlayerByData(playerData);
            var tipText:String;
            var roleLevel:* = cache.role.entityInfo.level;
            switch(opName)
            {
                case ChatForbid:
                {
                    break;
                }
                case ChatUnForbid:
                {
                    break;
                }
                case ChatPirvate:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ChatPrivate, miniPlayer));
                    break;
                }
                case LookInfo:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.LookPlayerInfo, miniPlayer));
                    break;
                }
                case AddFriend:
                {
                    if (roleLevel < GameConst.FriendOpenLevel)
                    {
                        MsgManager.showRollTipsMsg(Language.getStringByParam(20756, GameConst.FriendOpenLevel));
                        break;
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.FriendApply, miniPlayer.name));
                    break;
                }
                case AddIntimateFriend:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ModifyFriendType, playerData));
                    break;
                }
                case LowerToFriend:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ModifyFriendType, playerData));
                    break;
                }
                case Trade:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.TradeApplyToTarget, miniPlayer.entityId));
                    break;
                }
                case SendLetter:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.MailMenuSend, miniPlayer.name));
                    break;
                }
                case CopyName:
                {
                    System.setClipboard(miniPlayer.name);
                    break;
                }
                case InvitedToTeam:
                {
                    arr = new Array();
                    sGroupOper = new SGroupOper();
                    sGroupOper.fromEntityId = Cache.instance.role.entityInfo.entityId;
                    sGroupOper.toEntityId = miniPlayer.entityId;
                    sGroupOper.fromPlayer = new SPublicPlayer();
                    sGroupOper.fromPlayer.entityId = Cache.instance.role.entityInfo.entityId;
                    sGroupOper.type = EGroupOperType._EGroupOperTypeInvite;
                    sGroupOper.fromPlayer.guildId = new SEntityId();
                    sGroupOper.fromPlayer.copyId = new SEntityId();
                    arr.push(sGroupOper);
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GroupInviteOper, arr));
                    break;
                }
                case ApplyToTeam:
                {
                    arr2 = new Array();
                    sGroupOper2 = new SGroupOper();
                    sGroupOper2.fromEntityId = Cache.instance.role.entityInfo.entityId;
                    sGroupOper2.toEntityId = miniPlayer.entityId;
                    sGroupOper2.fromPlayer = new SPublicPlayer();
                    sGroupOper2.fromPlayer.entityId = Cache.instance.role.entityInfo.entityId;
                    sGroupOper2.fromPlayer.guildId = new SEntityId();
                    sGroupOper2.fromPlayer.copyId = new SEntityId();
                    sGroupOper2.type = EGroupOperType._EGroupOperTypeApply;
                    arr2.push(sGroupOper2);
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GroupApplyOper, arr2));
                    break;
                }
                case GuildInvite:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GUILD_INVITE, {id:miniPlayer.entityId.id, type:EInviteMode._EInviteForJoinGuild}));
                    break;
                }
                case GuildApply:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GUILD_APPLY_BY_ROLE, miniPlayer.entityId.id));
                    break;
                }
                case MoveToBlackList:
                {
                    if (roleLevel < GameConst.FriendOpenLevel)
                    {
                        MsgManager.showRollTipsMsg(Language.getStringByParam(20756, GameConst.FriendOpenLevel));
                        break;
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.AddToBlackList, playerData));
                    break;
                }
                case Delete:
                case Delete2:
                case Remove:
                {
                    Alert.show(Language.getStringByParam(20757, miniPlayer.name), null, Alert.OK | Alert.CANCEL, null, onClickHandler);
                    break;
                }
                case LeaveGroup:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GroupLeave));
                    break;
                }
                case KickOutGroup:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GroupKickOut, miniPlayer.entityId));
                    break;
                }
                case CreateGroup:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GroupCreateGroup));
                    break;
                }
                case AppointCaptain:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GroupModifyCaptain, miniPlayer.entityId));
                    break;
                }
                case HandselFlower:
                {
                    break;
                }
                case ChristmasCard:
                {
                    break;
                }
                case LookMember:
                {
                    break;
                }
                case Battle:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.BattleApply, miniPlayer.entityId));
                    break;
                }
                case DisBandGroup:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GroupDisbanGroup));
                    break;
                }
                case CopyName:
                {
                    System.setClipboard(miniPlayer.name);
                    break;
                }
                case GuildInviteCreate:
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GUILD_INVITE, {id:miniPlayer.entityId.id, type:EInviteMode._EInviteForCreateGuild}));
                    break;
                }
                case FlowerSend:
                {
                    flowerData = new FlowerSendData();
                    flowerData.toPlayer = miniPlayer;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.FlowerOpenWin, flowerData));
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public static function getOpEnabled(param1:String, param2) : Boolean
        {
            var _loc_3:* = getMiniPlayerByData(param2);
            switch(param1)
            {
                case ChatForbid:
                {
                    return false;
                }
                case ChatUnForbid:
                {
                    return false;
                }
                case ChatPirvate:
                {
                    return isAtSamePlat(_loc_3) && !isSelf(_loc_3);
                }
                case LookInfo:
                {
                    return !isSelf(_loc_3) && _loc_3.entityId != null && !EntityUtil.isSelf(_loc_3.entityId) && !EntityUtil.isMercenary(_loc_3.entityId);
                }
                case AddFriend:
                {
                    return !isSelf(_loc_3) && isAtSameServer(_loc_3);
                }
                case AddIntimateFriend:
                {
                    return true;
                }
                case LowerToFriend:
                {
                    return true;
                }
                case Trade:
                {
                    return isAtSameServer(_loc_3) && !isBlackList(_loc_3) && !isSelf(_loc_3);
                }
                case SendLetter:
                {
                    return isAtSameServer(_loc_3) && !isBlackList(_loc_3) && !isSelf(_loc_3);
                }
                case CopyName:
                {
                    return true;
                }
                case InvitedToTeam:
                {
                    return isCanInvitedToTeam(_loc_3);
                }
                case ApplyToTeam:
                {
                    return isCanApplyToTeam(_loc_3);
                }
                case GuildInvite:
                {
                    if (ClockManager.instance.serverOpenDateNum < 3)
                    {
                        return false;
                    }
                    return !isSelf(_loc_3) && isAtSameServer(_loc_3) && cache.guild.canApplyToGuild(_loc_3);
                }
                case GuildApply:
                {
                    if (isSelf(_loc_3))
                    {
                        return false;
                    }
                    if (!isAtSameServer(_loc_3))
                    {
                        return false;
                    }
                    if (cache.guild.selfGuildInfo.selfHasJoinGuild)
                    {
                        return false;
                    }
                    if (cache.role.roleInfo.level < GuildConst.CreateGuildRequireLevel)
                    {
                        return false;
                    }
                    return true;
                }
                case GuildInviteCreate:
                {
                    if (!isAtSameServer(_loc_3))
                    {
                        return false;
                    }
                    if (_loc_3.guildId > 0)
                    {
                        return false;
                    }
                    if (_loc_3.level < GameConst.TFreeCreateGuildInviteLevel)
                    {
                        return false;
                    }
                    if (cache.task.getTaskByCode(GameConst.TFreeCreateGuildTaskCode, true) == null)
                    {
                        return false;
                    }
                    return true;
                }
                case MoveToBlackList:
                {
                    return !isSelf(_loc_3) && isAtSameServer(_loc_3);
                }
                case Delete:
                {
                    return !isSelf(_loc_3);
                }
                case Delete2:
                {
                    return true;
                }
                case HandselFlower:
                {
                    return true;
                }
                case ChristmasCard:
                {
                    return true;
                }
                case LookMember:
                {
                    return true;
                }
                case Battle:
                {
                    return !isSelf(_loc_3);
                }
                case LeaveGroup:
                {
                    return cache.group.isInGroup && _loc_3.entityId.id == Cache.instance.role.entityInfo.entityId.id;
                }
                case CreateGroup:
                {
                    return !cache.group.isInGroup;
                }
                case DisBandGroup:
                {
                    return cache.group.isCaptain;
                }
                case KickOutGroup:
                {
                    return cache.group.isCaptain && _loc_3.entityId.id != Cache.instance.role.entityInfo.entityId.id;
                }
                case AppointCaptain:
                {
                    return cache.group.isCaptain && _loc_3.entityId.id != Cache.instance.role.entityInfo.entityId.id && _loc_3.online;
                }
                case FlowerSend:
                {
                    return _loc_3.online && isAtSameServer(_loc_3) && !isSelf(_loc_3);
                }
                default:
                {
                    return true;
                    break;
                }
            }
        }// end function

        private static function isCanInvitedToTeam(param1:SMiniPlayer) : Boolean
        {
            if (isSelf(param1) || !param1.online || !isAtSameServer(param1))
            {
                return false;
            }
            if (param1 is MiniPlayerInfo && (param1 as MiniPlayerInfo).groupId && (param1 as MiniPlayerInfo).groupId.id)
            {
                return false;
            }
            return cache.group.isInGroup && !cache.group.isCaptain && !cache.group.memberInvite ? (false) : (true);
        }// end function

        private static function isCanApplyToTeam(param1:SMiniPlayer) : Boolean
        {
            if (isSelf(param1) || !param1.online || !isAtSameServer(param1))
            {
                return false;
            }
            return cache.group.players.length > 0 ? (false) : (true);
        }// end function

        private static function isSelf(param1:SMiniPlayer) : Boolean
        {
            return EntityUtil.equal(param1.entityId, cache.role.entityInfo.entityId) ? (true) : (false);
        }// end function

        private static function isBlackList(param1:SMiniPlayer) : Boolean
        {
            return Cache.instance.friend.isBlackList(param1.entityId);
        }// end function

        private static function isAtSameServer(param1:SMiniPlayer) : Boolean
        {
            return param1.entityId.typeEx2 == cache.role.entityInfo.entityId.typeEx2 && param1.entityId.typeEx == cache.role.entityInfo.entityId.typeEx;
        }// end function

        private static function isAtSamePlat(param1:SMiniPlayer) : Boolean
        {
            return param1.entityId.typeEx2 == cache.role.entityInfo.entityId.typeEx2;
        }// end function

    }
}
